CREATE TABLE TBL_n0(C1 INT, C2 INT, C3 INT, C4 INT);

CREATE TABLE DEST1_n116(d1 INT, d2 INT) STORED AS TEXTFILE;
CREATE TABLE DEST2_n30(d1 INT, d2 INT, d3 INT) STORED AS TEXTFILE;
CREATE TABLE DEST3_n4(d1 INT, d2 INT, d3 INT, d4 INT) STORED AS TEXTFILE;
CREATE TABLE DEST4(d1 INT, d2 INT, d3 INT, d4 INT) STORED AS TEXTFILE;

EXPLAIN
FROM TBL_n0
INSERT OVERWRITE TABLE DEST1_n116 SELECT TBL_n0.C1, COUNT(TBL_n0.C2) GROUP BY TBL_n0.C1
INSERT OVERWRITE TABLE DEST2_n30 SELECT TBL_n0.C1, TBL_n0.C2, COUNT(TBL_n0.C3) GROUP BY TBL_n0.C1, TBL_n0.C2;

EXPLAIN
FROM TBL_n0
INSERT OVERWRITE TABLE DEST1_n116 SELECT TBL_n0.C1, COUNT(TBL_n0.C2) GROUP BY TBL_n0.C1
INSERT OVERWRITE TABLE DEST2_n30 SELECT TBL_n0.C1, TBL_n0.C2, COUNT(TBL_n0.C3) GROUP BY TBL_n0.C2, TBL_n0.C1;

EXPLAIN
FROM TBL_n0
INSERT OVERWRITE TABLE DEST3_n4 SELECT TBL_n0.C1, TBL_n0.C2, TBL_n0.C3, COUNT(TBL_n0.C4) GROUP BY TBL_n0.C1, TBL_n0.C2, TBL_n0.C3
INSERT OVERWRITE TABLE DEST2_n30 SELECT TBL_n0.C1, TBL_n0.C2, COUNT(TBL_n0.C3) GROUP BY TBL_n0.C1, TBL_n0.C2;

EXPLAIN
FROM TBL_n0
INSERT OVERWRITE TABLE DEST3_n4 SELECT TBL_n0.C1, TBL_n0.C2, TBL_n0.C3, COUNT(TBL_n0.C4) GROUP BY TBL_n0.C1, TBL_n0.C2, TBL_n0.C3
INSERT OVERWRITE TABLE DEST4 SELECT TBL_n0.C1, TBL_n0.C2, TBL_n0.C3, COUNT(TBL_n0.C4) GROUP BY TBL_n0.C1, TBL_n0.C3, TBL_n0.C2;


EXPLAIN
FROM TBL_n0
INSERT OVERWRITE TABLE DEST3_n4 SELECT TBL_n0.C1, TBL_n0.C2, TBL_n0.C3, COUNT(TBL_n0.C4) GROUP BY TBL_n0.C1, TBL_n0.C2, TBL_n0.C3
INSERT OVERWRITE TABLE DEST2_n30 SELECT TBL_n0.C1, TBL_n0.C2, COUNT(TBL_n0.C3) GROUP BY TBL_n0.C1, TBL_n0.C2
INSERT OVERWRITE TABLE DEST1_n116 SELECT TBL_n0.C1, COUNT(TBL_n0.C2) GROUP BY TBL_n0.C1;
